﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using ET;
using System.Data.SqlClient;
namespace DA
{
    public class Order_Buy_DAL : clsConnect
    {
        private clsConnect cls = new clsConnect();
        #region[Get-Data]
        public DataTable GetOrderBuy()
        {
            return cls.GetData("sp_tb_Order_Buy");
        }
        public DataTable GetOrderBuyEdit(int id)
        {
            return cls.GetData_ID_Int("sp_tb_Order_Buy_Edit", "@Order_Buy_Id", id);
        }
        public DataTable GetOrderBuyOrderOfOrder(int id)
        {
            return cls.GetData_ID_Int("sp_tb_Order_Buy_Of_Order", "@Order_Id", id);
        }
        public DataTable GetOrderBuyDetail(int id)
        {
            return cls.GetData_ID_Int("sp_tb_Order_Buy_Detail", "@Order_Buy_Id", id);
        }
        #endregion

        #region[Insert-Update-Delete]
        public bool InsertOrderBy(Order_Buy_ET data)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = GetConnection();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "tb_Order_Buy_Insert";

            cmd.Parameters.Add("@Order_Id", SqlDbType.Int).Value = data.Order_Id;
            cmd.Parameters.Add("@Order_Buy_Code", SqlDbType.NVarChar).Value = data.Order_Buy_Code;
            cmd.Parameters.Add("@Order_Buy_DateBegin", SqlDbType.DateTime).Value = data.Order_Buy_DateBegin;
            cmd.Parameters.Add("@Order_Buy_DateEnd", SqlDbType.DateTime).Value = data.Order_Buy_DateEnd;
            cmd.Parameters.Add("@Order_Buy_Tax_Code", SqlDbType.NVarChar).Value = data.Order_Buy_Tax_Code;
            cmd.Parameters.Add("@Order_Buy_Description", SqlDbType.NVarChar).Value = data.Order_Buy_Description;
            cmd.Parameters.Add("@Order_Buy_Payment_Type", SqlDbType.NVarChar).Value = data.Order_Buy_Payment_Type;
            cmd.Parameters.Add("@Order_Buy_Uesr_ID", SqlDbType.Int).Value = data.Order_Buy_Uesr_ID;
            cmd.Parameters.Add("@Customer_ID", SqlDbType.Int).Value = data.Customer_ID;
            cmd.Parameters.Add("@Order_Buy_Id", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();
            data.Order_Buy_Id = int.Parse(cmd.Parameters["@Order_Buy_Id"].Value.ToString());
            return true;
        }
        public bool DeleteOrderBuy(int id)
        {
            cls.Delete("sp_tb_Order_Buy_Delete", "@Order_Buy_Id", id);
            return true;
        }
        
        #endregion

        #region[Search-Fillter]
        public DataTable SearchOrder(string keywords)
        {
            return cls.Search("sp_tb_Order_Buy", "@KEYWORDS", keywords);
        }
        #endregion
    }
}
